package com.zhitan.ems.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.influxdb.client.InfluxDBClient;
import com.influxdb.client.InfluxDBClientFactory;
/**
 * InfluxDB配置类
 */
@Configuration
@ConditionalOnProperty(prefix = "influx", name = "enabled", havingValue = "true")
public class InfluxDBConfig {
    @Value("${influx.url}")
    private String url;

    @Value("${influx.token}")
    private String token;

    @Value("${influx.org}")
    private String org;

    @Value("${influx.bucket}")
    private String bucket;
    @Bean
    public InfluxDBClient influxDBClient() {
        // 使用简单的工厂方法创建客户端
        InfluxDBClient client = InfluxDBClientFactory.create(
                url,
                token.toCharArray(),
                org,
                bucket
        );
        return client;
    }
}